<?php

use kzo\base\widgets\ui\common\grid\GridView;
use yii\bootstrap\Modal;
use yii\helpers\Html;
use yii\helpers\Url;
use kzo\base\models\statics\EntityModelStatus;
use kzo\base\models\statics\OperationEvent;
use kzo\base\widgets\ui\common\grid\ActionColumn;

/* @var $this yii\web\View */
/* @var $searchModel common\models\c2\search\ProductSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
/* @var $model common\models\c2\search\ProductSearch */

?>
<div class="product-package-index">

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <?php echo GridView::widget([
        'dataProvider' => $dataProvider,
        // 'filterModel' => $searchModel,
        // 'id' => 'product-package-grid',
        'pjax' => true,
        'hover' => true,
        'showPageSummary' => true,
        'panel' => ['type' => GridView::TYPE_PRIMARY, 'heading' => Yii::t('app.c2', 'Items')],
        'toolbar' => [
            [
                'content' =>
                    Html::a(Yii::t('app.c2', 'Add Product Package'), ['package/edit', 'product_id' => $model->id], [
                        'class' => 'btn btn-primary package',
                        'title' => Yii::t('app.c2', 'Add Sale Product'),
                        'data-pjax' => '0',
                    ]) . ' ' .
                    // Html::button('<i class="fas fa-minus"></i>', [
                    //     'class' => 'btn btn-danger',
                    //     'title' => Yii::t('app.c2', 'Delete Selected Items'),
                    //     'onClick' => "jQuery(this).trigger('" . OperationEvent::DELETE_BY_IDS . "', {url:'" . Url::toRoute('multiple-delete') . "'});",
                    // ]) . ' ' .
                    Html::a('<i class="fas fa-redo"></i>', Url::current(), [
                        'class' => 'btn btn-outline-secondary',
                        'id' => 'product-package-grid-fresh',
                        'title' => Yii::t('app.c2', 'Reset Grid')
                    ]),
                'options' => ['class' => 'btn-group mr-2']
            ],
            // '{export}',
            // '{toggleData}',
        ],
        'exportContainer' => ['class' => 'btn-group mr-2'],
        'exportConfig' => [],
        'columns' => [
            // ['class' => 'kartik\grid\CheckboxColumn'],
            // ['class' => 'kartik\grid\SerialColumn'],
            // [
            //     'class' => 'kartik\grid\ExpandRowColumn',
            //     'value' => function ($model, $key, $index, $column) {
            //         return GridView::ROW_COLLAPSED;
            //     },
            //     'detail' => function ($model, $key, $index, $column) {
            //         return Yii::$app->controller->renderPartial('_detail', ['model' => $model]);
            //     },
            // ],
            // 'id',
            // 'type',
            'label',
            'capacity',
            'weight',
            'volume',
            'unit',
            // 'created_at',
            // 'updated_at',
            [
                'attribute' => 'status',
                'class' => '\kartik\grid\EditableColumn',
                'editableOptions' => [
                    'inputType' => \kartik\editable\Editable::INPUT_DROPDOWN_LIST,
                    'formOptions' => ['action' => Url::toRoute('package/editColumn')],
                    'data' => EntityModelStatus::getHashMap('id', 'label'),
                    'displayValueConfig' => EntityModelStatus::getHashMap('id', 'label'),
                ],
                'filter' => EntityModelStatus::getHashMap('id', 'label'),
                'value' => function ($model) {
                    return $model->getStatusLabel();
                }
            ],
            [
                'class' => ActionColumn::className(),
                'width' => '150px',
                'template' => '{update}',
                'buttons' => [
                    'update' => function ($url, $model, $key) {
                        return Html::a('<span class="fas fa-pencil-alt"></span>', ['package/edit', 'id' => $model->id], [
                            'title' => Yii::t('app', 'Edit'),
                            'data-pjax' => '0',
                            'class' => 'package'
                        ]);
                    }
                ]
            ],

        ],
    ]); ?>

</div>
<?php


Modal::begin([
    'id' => 'product-package-modal',
    'size' => 'modal-xl',
]);
Modal::end();

$js = "";

$js .= "jQuery(document).on('click', 'a.package', function(e) {
                e.preventDefault();
                jQuery('#product-package-modal').modal('show').find('.modal-content').html('" . Yii::t('app.c2', 'Loading...') . "').load(jQuery(e.currentTarget).attr('href'));
            });";

$this->registerJs($js);

?>